
<template>
  <div>
    <div class="title">
      <div class="serve">
        <div class="name">工单编号:</div>
        <div>
          <el-input v-model="input"  placeholder="请输入内容"></el-input>
        </div>
      </div>
      <div class="btn">
        <el-button type="primary" @click="sever(input)" icon="el-icon-search" size="medium"
          >搜索</el-button
        >
      </div>
    </div>
    <div class="main">
      <div class="top-btn">
        <el-button
          type="warning"
          icon="el-icon-circle-plus-outline"
          size="medium"
          @click="addFn"
          >新建</el-button
        >
      </div>
      <div class="count">
        <el-table :data="tableData" style="width: 100%">
          <el-table-column fixed prop="index" label="序号" width="80">
          </el-table-column>
          <el-table-column prop="name" label="合作商名称" width="226">
          </el-table-column>
          <el-table-column prop="account" label="账号" width="205">
          </el-table-column>
          <el-table-column prop="vmCount" label="设备数量" width="205">
          </el-table-column>
          <el-table-column prop="ratio" label="分成比例" width="205">
          </el-table-column>
          <el-table-column prop="contact" label="联系人" width="205">
          </el-table-column>
          <el-table-column prop="account" label="联系电话" width="205">
          </el-table-column>
          <el-table-column fixed="right" label="操作" width="230">
            <template slot-scope="scope">
              <el-button @click.native.prevent="resetPwd(scope.$index, tableData)" type="text" size="small">
                重置密码
              </el-button>
              <el-button @click.native.prevent="detail(scope.$index, tableData)" type="text" size="small">
                查看详细
              </el-button>
              <el-button @click.native.prevent="revise(scope.$index, tableData)" type="text" size="small">
                修改
              </el-button>
              <el-button
              style="color:red" @click.native.prevent="deleteRow(scope.$index, tableData)" type="text" size="small">
                删除
              </el-button>

            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>
     <Footer @next="next" @up="up" :number="number" :pageIndex="region.pageIndex"/>
     <Detail :visible.sync="reg.detail" :find ="find"/>
    <Revise :visible.sync="reg.revise" :change ="this.reg.change" @abst="abst"/>
  </div>
</template>

<script>
import { partner, del, resetPwd } from '@/api/getLevel/interIocal'
import Footer from '@/components/public/FtooTer.vue'
import Detail from '@/views/getLevel/components/interIocal-detail.vue'
import Revise from '@/views/getLevel/components/interIocal-revise.vue'
export default {
  components: {
    Footer,
    Detail,
    Revise
  },
  async created () {
    this.Data()
  },
  methods: {
    // 删除
    async deleteRow (index, rows) {
      await del(rows[index].id)
      this.Data()
    },
    // 接口渲染页面
    async Data () {
      const res = await partner(this.region)
      this.tableData = (res.currentPageRecords)// 对获取的数据添加序号属性
      this.tableData.forEach((item, index) => {
      // 添加序号
        this.$set(item, 'index', index + 1 + ((this.region.pageIndex - 1) * 10))
        // this.$set(item, 'index', index + 1)
      })
      // 总页数
      this.number = res.totalCount
    },
    // 下一页
    next () {
      this.region.pageIndex++
      // 页数
      this.Data()
    },
    // 上一页
    up () {
      this.region.pageIndex--
      // 页数
      this.Data()
    },
    // 搜索
    sever (input) {
      this.region.name = input
      this.Data()
    },
    // 新增
    addFn () {
      this.reg.revise = true
      this.reg.change.show = false
    },
    // 查看
    async detail (index, rows) {
      this.find = rows[index]
      this.reg.detail = true
    },
    // 修改
    revise (index, rows) {
      this.reg.revise = true
      this.reg.change.show = true
      this.reg.change.id = rows[index].id
      this.reg.change.name = rows[index].name
      this.reg.change.ratio = rows[index].ratio
      this.reg.change.contact = rows[index].contact
      this.reg.change.mobile = rows[index].mobile
      this.reg.change.phone = rows[index].mobile
      console.log(this.reg.change)
    },
    // 重置合作商密码
    async resetPwd (index, rows) {
      console.log(rows[index])
      const res = await resetPwd(rows[index].id)
      console.log(res)
    },
    // 新增&查看
    abst () {
      this.Data()
    }
  },

  data () {
    return {
      // 增删改查
      reg: {
        detail: false,
        revise: false,
        change: {
          id: '',
          show: false,
          account: '',
          contact: '',
          mobile: '',
          name: '',
          password: '',
          ratio: '',
          phone: ''
        }
      },
      input: '',
      number: '', // 总条数
      now: '', // 当前页数
      // 请求参数
      region: {
        pageIndex: 1,
        pageSize: 10,
        name: '',
        regionId: ''
      },
      tableData: [],
      find: {}
    }
  }
}
</script>

<style lang="scss" scoped>
.title {
  width: 100%;
  background-color: #fff;
  height: 9.5%;
  margin-bottom: 1.2%;
  display: flex;
  line-height: 64px;
  .serve {
    display: flex;
    margin-right: 10px;
    .name {
      width: 35%;
      font-size: 14px;
    }
  }
}
.main {
  height: 90%;
  width: 100%;
  background-color: #fff;
  .top-btn {
    display: flex;
    width: 100%;
    height: 7%;
    margin-left: 10px;
    margin-bottom: 16px;
    // background-color: red;
  }
  .count {
    height: 93%;
  }
}
</style>
